import QtQuick 2.6
import QtQuick.Controls 1.5
import QtQuick.Layouts 1.1
import QtQuick.Window 2.0
import QtWebView 1.1

import Cpp.Data 1.0 as Data

import Config 1.0

import "Main" as Main

ApplicationWindow {
    id: app

    function setStatus(text) {
        statusBar.text = text
    }

    x: 0
    y: 0
    width: 1120
    height: 750
    visible: true
    title: qsTr("Hello World")

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("&Open")
                onTriggered: console.log("Open action triggered")
            }
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit()
            }
        }
    }
    statusBar: StatusBar {
        id: statusBar
        property alias text: textLabel.text
        RowLayout {
            anchors.fill: parent
            Label {
                id: textLabel
                text: "Status bar"
            }
        }
    }
    Loader {
        Component.onCompleted: {
            Size.ratio = Qt.binding(function () {
                return height / 1280
            })
        }
        anchors.fill: parent
        sourceComponent: {
            if(Data.User.isAdmin)
                return mainIndexComponent
            return loginComponent
        }
        Component {
            id:loginComponent
            Login { }
        }
        Component {
            id:mainIndexComponent
            Main.Index { }
        }
    }

}
